package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.entity.TlGoods;
import com.qf.entity.TlGorderitem;
import com.qf.mapper.GoodsMapper;
import com.qf.mapper.GorderItemMapper;
import com.qf.service.GoodsService;
import com.qf.service.GorderItemService;
import com.qf.utils.Mycode;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GorderItemServiceImpl extends ServiceImpl<GorderItemMapper, TlGorderitem> implements GorderItemService {

    @Autowired(required = false)
    GorderItemMapper gorderItemMapper;
    @Autowired(required = false)
    GoodsMapper goodsMapper;
    @Override
    public ResultMsg selectOne(String gorderId) {
        QueryWrapper<TlGorderitem> wrapper = new QueryWrapper<>();
        wrapper.eq("gorder_id",gorderId);
        List<TlGorderitem> tlGorderitems = gorderItemMapper.selectList(wrapper);
        return ResultMsg.SUCCESS(tlGorderitems);
    }

    @Override
    public ResultMsg insert(Integer[] gid, String gOrderId, Integer[] number) {
        for (int i = 0; i < gid.length; i++) {
            TlGoods tlGoods = goodsMapper.selectById(gid[i]);
            TlGorderitem tlGorderitem = new TlGorderitem();
            tlGorderitem.setGorderId(gOrderId);
            tlGorderitem.setGorderitemName(tlGoods.getGoodsName());
            tlGorderitem.setGorderitemPrice(tlGoods.getGoodsPrice());
            tlGorderitem.setGorderitemPic(tlGoods.getGoodsPic1());
            tlGorderitem.setGorderitemNum(number[i]);
            tlGorderitem.setGorderitemInfo(tlGoods.getGoodsInfo());
            super.saveOrUpdate(tlGorderitem);
        }
        return ResultMsg.SUCCESS();
    }
}
